<template>
<div>
    <!-- 面包屑导航start -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>订单管理</el-breadcrumb-item>
          <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
    <!-- 面包屑导航end -->

     <!-- 卡片区域start -->
        <el-card>
            <!-- 搜索 -->
             <el-row :gutter="20">
                 <el-col :span="6">
                     <el-input placeholder="请输入内容"  clearable >
                         <el-button slot="append" icon="el-icon-search" ></el-button>
                     </el-input>
                 </el-col>
             </el-row>

        <!-- 主体内容区域start -->
             <el-table  :data="orderList" stripe  style="width: 100%" border>
                <el-table-column type="index" label="#" ></el-table-column>
                <el-table-column prop="order_number"  label="订单编号"  width="380"></el-table-column>
                <el-table-column prop="order_price" label="订单价格"  width="80"></el-table-column>
                <el-table-column prop="order_pay" label="是否付款" width="80"> </el-table-column>
                <el-table-column prop="is_send" label="是否发货" width="80"> </el-table-column>
                <el-table-column prop="create_time" label="下单时间" width="280">
                <template v-slot="{row}">
                       {{row.create_time | dateFormat}}
                   </template>
                </el-table-column>
                <el-table-column  label="操作">
                    <template v-slot="{row}">
                        <!-- 修改 -->
                      <el-button type="primary" icon="el-icon-edit" circle @click="showBox(row.id)"></el-button>
                        <!-- 物流进度 -->
                      <el-button type="success" icon="el-icon-location-outline" circle  @click="progreeShow"></el-button>
                    </template>
                </el-table-column>
            </el-table>
        <!-- 主体内容区域end -->

        <!-- 分页区域 start -->
         <el-pagination  @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryInfo.pagenum"  :page-sizes="[5, 12, 15, 20]" :page-size="queryInfo.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
        <!-- 分页区域 end-->
        </el-card>

    <!-- 卡片区域end -->

    <!-- 展示修改对话框start -->
      <el-dialog title="修改地址" :visible.sync="orderDialogVisible" width="50%" @close="orderClose">
          <el-form :model="eaitForm" :rules="eaitFormRules" ref="eaitFormRef" label-width="100px">
              <el-form-item label="省市区/县" prop="address1">
                  <el-cascader
                      v-model="eaitForm.address1"
                      :options="cityData"
                      :props="{ expandTrigger: 'hover' }"></el-cascader>
              </el-form-item>
              <el-form-item label="详细地址" prop="address2">
                  <el-input v-model="eaitForm.address2"></el-input>
              </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
              <el-button @click="orderDialogVisible = false">取 消</el-button>
              <el-button type="primary" @click="orderDialogVisible = false">确 定</el-button>
          </span>
      </el-dialog>
    <!-- 展示修改对话框end-->

    <!-- 展示物流进度start -->
      <el-dialog title="物流进度" :visible.sync="progreedialogVisible" width="50%">
        <!-- 时间线start -->
        <el-timeline>
          <el-timeline-item v-for="(activity, index) in progreeInfo" :key="index" :timestamp="activity.time">
            {{activity.context}}
          </el-timeline-item>
        </el-timeline>
      </el-dialog>
    <!-- 展示物流进度end -->

</div>
</template>

<script>
import cityData from './citydata.js'
export default {
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orderList: [],
      // 总条数
      total: 0,
      // 修改对话框显示与隐藏
      orderDialogVisible: false,
      eaitForm: {
        address1: [],
        address2: ''
      },
      // 修改校验规则
      eaitFormRules: {
        address1: [
          { required: true, message: '请选择省市区/县', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请填写详细地址', trigger: 'blur' }
        ]
      },
      cityData,
      progreedialogVisible: false,
      progreeInfo: []
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    // 获取订单列表
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表失败')
      }
      console.log(res)
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    handleCurrentChange (newNum) {
      this.queryInfo.pagenum = newNum
      this.getOrderList()
    },
    // 展示修改对话框显示与隐藏
    showBox (id) {
      console.log(id)
      this.orderDialogVisible = true
    },
    // 监听对话框关闭重置事件
    orderClose () {
      this.$refs.eaitFormRef.resetFields()
    },
    // 展示物流进度显示与隐藏
    async progreeShow () {
      const { data: res } = await this.$http.get('/kuaidi/804909574412544580')
      if (res.meta.status !== 200) {
        return this.$message.error('获取物流信息失败')
      }
      this.progreeInfo = res.data
      this.progreedialogVisible = true
      console.log(this.progreeInfo)
    }

  }
}
</script>

<style lang="less" scoped>
.el-cascader{
  width:100%;
}

</style>
